package com.icbc.cc.api;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

public class Test {
	

	
    public static void main(String args[]) throws ParseException {
    	String issueDate=null;
		String reaptDate=null;
		String tmpDate=null;
		String issueDateobj="2017-06-09 18:21:15";
		String reaptDateobj="2017-06-14 09:21:15";
		if(issueDateobj!=null && !"".equals(issueDateobj)){
			//发行时间
			issueDate =issueDateobj;
		}
		
		if(reaptDateobj!=null && !"".equals(reaptDateobj)){
			//重新预约时间
			reaptDate  =reaptDateobj;
		}  
		
		if(issueDate!=null && reaptDate==null){
			tmpDate=issueDate;
		}else if(issueDate==null && reaptDate!=null){
			tmpDate=reaptDate;
		}else if(issueDate!=null && reaptDate!=null){
			String a[]=new String[2];
			a[0]=issueDate;
			a[1]=reaptDate;
			tmpDate=daysBetween(a);
		}
		
		if(tmpDate!=null){
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String time= sdf.format(new Date());
			
			int value=compare_date(time,tmpDate);
			if(value<1){
				System.out.println("@@@@@@");;
			}
			
		}
    }
    
//    public static String getpath(){
//    	String rootPath=getClass().getResource("/").getFile().toString();
//    	return rootPath;
//    }
    
    public static int compare_date(String DATE1, String DATE2) {
        
        
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() > dt2.getTime()) {
                System.out.println("dt1 在dt2前");
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                System.out.println("dt1在dt2后");
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }
    
    public static String daysBetween(String[] date) throws ParseException{  
        String tmp="";
        for(int i=0;i<date.length-1;i++){
        	if(date[i]==null || "".equals(date[i])){
        		continue;
        	}
        	for(int j=i+1;j<date.length;j++){
        		if(date[j]==null || "".equals(date[j])){
            		continue;
            	}
        		if(compare_date(date[i],date[j])<0){
        			tmp=date[i];
        			date[i]=date[j];
        			date[j]=tmp;
        		}
        	}
        	
        }
        
       return date[0];     
    } 
    
}
